//Some static variables.
var MAXANIM = 10;
var MAXSIZE = 100;
var MINSIZE = 20;

function randomFromInterval(from, to) {
	return Math.floor(Math.random() * (to - from + 1) + from);
}

function lightsOn() {
	var i = 0;
	var delay = 0;
	return setInterval(function() {
		for ( i = 0; i < 6; i++) {
			$('div#page-menu table#menu-table #menu-cell_' + i + ' .effect').animate({
				backgroundColor : 'white'
			}, 200).delay(delay);
			$('div#page-menu table#menu-table #menu-cell_' + i + ' .effect').animate({
				backgroundColor : '#5E5E5E'
			}, 200);
			delay = delay + 500;
		}
		delay = 0;
	}, 5000);
}

function moveBackground(target_div) {
	var i = 0;
	var dim_ball;
	var moveX;
	var moveY;
	//	target_div dimentions.
	var content_width = $(target_div).width();
	var content_height = $(target_div).height();
	center_divX = content_width;
	center_divY = -content_height / 2;

	while (i < MAXANIM) {
		dim_ball = randomFromInterval(MINSIZE, MAXSIZE);
		center_divX = content_width - dim_ball;
		center_divY = -(content_height - dim_ball);
		moveX = randomFromInterval(0, center_divX);
		moveY = randomFromInterval(0, center_divY);

		$('#filled_ball-' + i).animate({
			'margin-top' : moveY + 'px',
			'margin-left' : moveX + 'px',
			'width' : dim_ball + 'px',
			'height' : dim_ball + 'px'
		}, 1000);

		dim_ball = randomFromInterval(MINSIZE, MAXSIZE);
		center_divX = content_width - dim_ball;
		center_divY = -(content_height - dim_ball);
		moveX = randomFromInterval(0, center_divX);
		moveY = randomFromInterval(0, center_divY);

		$('#stroke_ball-' + i).animate({
			'margin-top' : moveY + 'px',
			'margin-left' : moveX + 'px',
			'width' : dim_ball + 'px',
			'height' : dim_ball + 'px'
		}, 1000);

		i++;
	}
}

function animateBackground(target_div) {
	var i = 0;
	var moveX = -1;
	var moveY = -1;
	var center_divX;
	var center_divY;
	var dim_ball = MAXSIZE;
	var filled_ball = new Array();
	var stroke_ball = new Array();

	//	target_div dimentions.
	var content_width = $(target_div).width();
	var content_height = $(target_div).height();

	while (i < MAXANIM) {

		filled_ball[i] = $("<div class='filled_ball' id='filled_ball-" + i + "' ></div>");
		stroke_ball[i] = $("<div class='stroke_ball' id='stroke_ball-" + i + "' ></div>");

		$(target_div).append(filled_ball[i], stroke_ball[i]);

		center_divX = (content_width / 2);
		center_divY = -(content_height / 2);

		filled_ball[i].css({
			'opacity' : '0',
			'margin-top' : center_divY + 'px',
			'margin-left' : center_divX + 'px'
		}).animate({
			'opacity' : '1',
			'width' : dim_ball + 'px',
			'height' : dim_ball + 'px'
		}, 500);

		stroke_ball[i].css({
			'margin-top' : center_divY + 'px',
			'margin-left' : center_divX + 'px',
			'width' : dim_ball + 'px',
			'height' : dim_ball + 'px'
		});

		dim_ball = randomFromInterval(MINSIZE, MAXSIZE);

		center_divX = content_width - dim_ball;
		center_divY = -(content_height - dim_ball);
		moveX = randomFromInterval(0, center_divX);
		moveY = randomFromInterval(0, center_divY);

		filled_ball[i].animate({
			'margin-top' : moveY + 'px',
			'margin-left' : moveX + 'px',
			'width' : dim_ball + 'px',
			'height' : dim_ball + 'px'
		}, 1000);

		dim_ball = randomFromInterval(MINSIZE, MAXSIZE);

		center_divX = content_width - dim_ball;
		center_divY = -(content_height - dim_ball);
		moveX = randomFromInterval(0, center_divX);
		moveY = randomFromInterval(0, center_divY);

		stroke_ball[i].animate({
			'margin-top' : moveY + 'px',
			'margin-left' : moveX + 'px',
			'width' : dim_ball + 'px',
			'height' : dim_ball + 'px'
		}, 1000);
		i++;
	}
}